package com.study.controller;

import com.study.entity.BusReceiverEntity;
import com.study.service.BusReceiverService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
public class MyController {

    @Autowired
    BusReceiverService busReceiverService;

    @RequestMapping("/findById/{id}")
    public BusReceiverEntity findById(@PathVariable Integer id) {
        return (BusReceiverEntity) busReceiverService.findById(id);
    }

    @RequestMapping("/delete/{id}")
    public String deleteById(@PathVariable Integer id) {
        busReceiverService.delete(id);
        return "success";

    }

    @RequestMapping("/insert/{name}/{regionCode}/{address}")
    public String insert(@PathVariable String name, @PathVariable String regionCode, @PathVariable String address) {
        BusReceiverEntity receiverEntity = new BusReceiverEntity(name, regionCode, address);
        busReceiverService.insert(receiverEntity);
        return "success";

    }

    @RequestMapping("/findList/{name}/{address}")
    public List<BusReceiverEntity> findList(@PathVariable String name, @PathVariable String address) {
        return busReceiverService.findList(name, address);
    }

    @RequestMapping("/findListByPage/{currPage}/{pageSize}")
    public List<BusReceiverEntity> findListByPage(@PathVariable Integer currPage, @PathVariable Integer pageSize) {
        return busReceiverService.findListByPage(currPage, pageSize);
    }

    @RequestMapping("/findAll")
    public List<BusReceiverEntity> findAll() {
        return busReceiverService.findAll();
    }


}
